﻿using SWENAssignment.Sophia.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SWENAssignment.Sophia
{
    public partial class addRoomReservation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblReservationID.Text = Request.QueryString["reservationID"];
            roomReservation r = DBmanager.getRoomReservationByID(lblReservationID.Text);
            if (!IsPostBack)
            {
                ddlNumOfAdults.SelectedValue = Convert.ToString(r.NumOfAdults);
                ddlNumOfChildren.SelectedValue = Convert.ToString(r.NumOfChildren);
                ddlPrefRoomType.SelectedValue = r.PreferredRoomType;
                ddlPrefBedType.SelectedValue = r.PreferredBedType;
                ddlSmokingOrNot.SelectedValue = r.SmokingOrNot;
            }


        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            roomReservation updateRoomReservation = new roomReservation();
            updateRoomReservation.ReservationID = lblReservationID.Text;
            updateRoomReservation.NumOfAdults = Convert.ToInt32(ddlNumOfAdults.SelectedValue);
            updateRoomReservation.NumOfChildren = Convert.ToInt32(ddlNumOfChildren.SelectedValue);
            updateRoomReservation.PreferredRoomType = ddlPrefRoomType.SelectedValue;
            updateRoomReservation.PreferredBedType = ddlPrefBedType.SelectedValue;
            updateRoomReservation.SmokingOrNot = ddlSmokingOrNot.SelectedValue;

            if (DBmanager.updateRoomReservation(updateRoomReservation) == 1)
            {
                Session["reservationID"] = updateRoomReservation.ReservationID;
                Server.Transfer("~/Sophia/editRoomReservationSuccessfully.aspx");
            }
            else
            {
                lblStatus.Text = "Unable to update!";
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Sophia/retrieveRoomReservation.aspx?");

        }
    }
}